const teamService = require('../services/teamService');

/**
 * TeamController
 * Controller 是业务入口，由 HTTP 路由解析后调用
 * 包含待办事项的增删改查功能
 */
class TeamController {
  /**
   * 通过名称查询队伍信息
   */
   async listAll(ctx) {
    const teamList = await teamService.listAll();
    ctx.body = {teamList};
  }

  /**
   * 查询队伍信息
   */
  async get(ctx) {
    const teamList = await teamService.get(ctx.params.userid);
    ctx.body = {teamList};
  }

  /**
 * 创建队伍
 */
  async add(ctx) {
    const teamInfo = ctx.request.body;
    const result = await teamService.add(teamInfo);
    ctx.body = {result};
  }

  /**
* 修改队伍信息
*/
  async edit(ctx) {
    const editInfo = ctx.request.body;
    const result = await teamService.edit(editInfo);
    ctx.body={result}
  }

  /**
* 删除队伍信息
*/
  async del(ctx) {
    const teamInfo = ctx.request.body;
    const teamid = teamInfo.teamid;
    const delStaus = await teamService.del(teamid);
    ctx.body={delStaus};
  }

  /**
  * 查询回复信息
  */
  async getReply(ctx) {
    const teamReplyList = await teamService.getReply(ctx.params.teamid);
    ctx.body = {teamReplyList};
  }

  /**
  * 创建信息回复
  */
  async addReply(ctx) {
    const replyInfo = ctx.request.body;
    const result = await teamService.addReply(replyInfo);
    ctx.body={result}
  }

  /**
  * 删除信息回复
  */
  async delReply(ctx) {
    const replyInfo = ctx.request.body;
    const replyID = replyInfo.teamreplyID;
    const delStaus = await teamService.delReply(replyID);
    ctx.body={delStaus};
  }

  /**
  * 修改信息回复
  */
  async editReply(ctx) {
    const editInfo = ctx.request.body;
    const result = await teamService.editReply(editInfo);
    ctx.body={result}
  }

  /**
  * 加入队伍
  */
  async join(ctx) {
    const info = ctx.request.body;
    const result = await teamService.join(info);
    ctx.body={result}
  }

  /**
  * 退出队伍
  */
  async quit(ctx) {
    const info = ctx.request.body;
    const result = await teamService.quit(info);
    ctx.body={result}
  }

}

// 导出 Controller 的实例
module.exports = new TeamController();
